package fudan.se.project.service.infrastructure.entity.sysrole;


import fudan.se.project.domain.sysrole.SystemAuthority;
import fudan.se.project.repository.entity.sysrole.SystemAuthorityRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SystemAuthorityService {

    private final SystemAuthorityRepository systemAuthorityRepository;

    @Autowired
    public SystemAuthorityService(SystemAuthorityRepository systemAuthorityRepository) {
        this.systemAuthorityRepository = systemAuthorityRepository;
    }

    public SystemAuthority getSystemAuthority(SystemAuthority.Authority authority) {
        SystemAuthority systemAuthority = systemAuthorityRepository.findByAuthority(authority);
        if (systemAuthority == null) {
            systemAuthority = systemAuthorityRepository.save(new SystemAuthority(authority));
        }

        return systemAuthority;
    }
}
